<?php
/*
**查询青岛海底世界已过期与未使用，更新订单状态
**2015-09-10 pm
**User By  PZP
*/
// $time_1 = microtime(true);
include('/var/www/html/new/d/module/api/QD_underwater_world/QD.class.php');
include('/var/www/html/new/d/module/api/function.class.php');
if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}

$QD = new QD_underW_World();
$PFT_infunction = new AllFunction();
$selorder = "select apiCode,pftOrder from all_api_order where coopB=4 and oStatus= 0";
$GLOBALS['le']->query($selorder);
while($row = $GLOBALS['le']->fetch_assoc()){
	$Orders[] = $row;
}

foreach($Orders  as $arr){
	$getOrderStatus = $QD->GetAllOrderStatus($arr['apiCode']);	
	$OrderStatus = $getOrderStatus[0]['OrderStatus'];
	if($OrderStatus == 'O'){ //线下已换票，需更新票付通状态
		$pft_order_xml = $PFT_infunction->Select_PFTorder($arr['pftOrder']);	
		$chkIns = 499;
		if((string)$pft_order_xml->Rec->UUstatus==2) $chkIns = 498;
		$UUordernum = (string)$pft_order_xml->Rec->UUordernum;
		$UUsalerid = (string)$pft_order_xml->Rec->UUsalerid;
		$UUcode = (string)$pft_order_xml->Rec->UUcode;
		$r = $PFT_infunction->Unified_Check_IN($UUsalerid,$UUcode,date('Y-m-d H:i:s'),$chkIns);
		if($r == 100){
			$selorder = "update all_api_order  set oStatus=1 where pftOrder='$UUordernum' limit 1";
			$GLOBALS['le']->query($selorder);
		}
		logfile($UUordernum."|".$r,"QD_checkOrder");
	}
	usleep(100);
}
// echo microtime(true) - $time_1;
function logfile($word,$path){
	$filepath= '/var/www/html/new/d/logs/api/Unified_entrance/'.$path.'.txt';
	if(file_exists($filepath)){
		$word = date("Y-m-d H:i:s")."|".$word;
		$word = mb_convert_encoding($word, 'GBK', 'UTF-8');
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
		{
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
			$handler=fopen($filepath,'w');
			flock($handler, LOCK_EX) ;
			fwrite($handler,"\n".$word);
			flock($handler, LOCK_UN);
			fclose($handler);
		}
		else
		{
			$fp = fopen('/var/www/html/new/d/logs/api/Unified_entrance/'.$path.'.txt',"a");
			flock($fp, LOCK_EX);
			fwrite($fp,$word."\n");
			flock($fp, LOCK_UN);
			fclose($fp);
		}
	}else{
		$fp = fopen('/var/www/html/new/d/logs/api/Unified_entrance/'.$path.'.txt',"a");
		flock($fp, LOCK_EX);
		fwrite($fp,date('Y-m-d H:i:s')."|".$word."\n");
		flock($fp, LOCK_UN);
		fclose($fp);
	}
}

?>